package io.openkunlun.javadsl.server;

import io.grpc.Metadata;
import io.grpc.ServerCall;
import io.grpc.ServerCallHandler;
import io.grpc.ServerInterceptor;
import io.openkunlun.javadsl.Context;
import io.openkunlun.javadsl.DaprContext;

/**
 * @author Srowen
 * @date Created on 2022/3/15
 * @description
 */
public class DaprServerContextInterceptor implements ServerInterceptor {

    @Override
    public <ReqT, RespT> ServerCall.Listener<ReqT> interceptCall(ServerCall<ReqT, RespT> serverCall, Metadata metadata, ServerCallHandler<ReqT, RespT> serverCallHandler) {
        Context context = Context.fork();
        context.putLocal(DaprContext.METADATA, metadata);
        return DaprContext.interceptCall(context, serverCall, metadata, serverCallHandler);
    }
}
